home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / Libraries / PlayerPRO 4.4.1 / Filters Plugs / Backwards.c < prev    next >
C/C++ Source or Header  |  1995-04-16  |  2KB  |  79 lines

  1. /*    Backwards        */
  2. /*    v 0.2            */
  3. /*    1995 by Liane    */
  4.  
  5. //    Usage:
  6. //    Invert the selected part or all the waveform if
  7. //    there is no selection.
  8.  
  9. #include "MAD.h"
  10. #include "PPPlug.h"
  11.  
  12. #if defined(powerc) || defined(__powerc)
  13. enum {
  14.         PlayerPROPlug = kCStackBased
  15.         | RESULT_SIZE(SIZE_CODE( sizeof(OSErr)))
  16.         | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof( Ptr*)))
  17.         | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof( struct FileInstrData*)))
  18.         | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof( long)))
  19.         | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof( long)))
  20.         | STACK_ROUTINE_PARAMETER(5, SIZE_CODE(sizeof( PPInfoPlug*)))
  21. };
  22.  
  23. ProcInfoType __procinfo = PlayerPROPlug;
  24. #else
  25. #include <A4Stuff.h>
  26. #endif
  27.  
  28.  
  29. OSErr main(     Ptr                        *InstrumentPtr,
  30.                 struct FileInstrData    *theData,
  31.                 long                    SelectionStart,
  32.                 long                    SelectionEnd,
  33.                 PPInfoPlug                *thePPInfoPlug)
  34. {
  35.     long    i;
  36.     unsigned short    temp1, temp2;
  37.  
  38.     if (SelectionStart == SelectionEnd) {
  39.         SelectionStart = 0;
  40.         SelectionEnd = theData->insSize;
  41.     }
  42.  
  43.     switch( theData->amplitude)
  44.     {
  45.         case 8:
  46.         {
  47.             Ptr    orgPtr = *InstrumentPtr, destPtr = orgPtr;
  48.  
  49.             orgPtr += SelectionStart;
  50.             destPtr += SelectionEnd - 1;
  51.             
  52.             for( i = 0; i < (SelectionEnd - SelectionStart) / 2; i++)    //just swap values
  53.             {
  54.                 temp1 = *orgPtr;
  55.                 temp2 = *destPtr;
  56.                 *orgPtr++ = temp2;
  57.                 *destPtr-- = temp1;
  58.             }
  59.         } break;
  60.         
  61.         case 16:
  62.         {
  63.             unsigned short    *orgPtr = (unsigned short*) *InstrumentPtr, *destPtr = orgPtr;
  64.  
  65.             orgPtr += SelectionStart / 2;
  66.             destPtr += (SelectionEnd - 1) / 2;
  67.             
  68.             for( i = 0; i < (SelectionEnd - SelectionStart) / 4; i++)
  69.             {
  70.                 temp1 = *orgPtr;
  71.                 temp2 = *destPtr;
  72.                 *orgPtr++ = temp2;
  73.                 *destPtr-- = temp1;
  74.             }
  75.         } break;
  76.     }
  77.  
  78.     return noErr;
  79. }